import re

s = '''
# 贪吃蛇游戏 HTML 实现

以下是一个完整的贪吃蛇游戏
HTML
实现，所有代码都在一个
HTML
文件中：

```html
< !DOCTYPE
html >
< html
lang = "zh-CN" >
< head >
< meta
charset = "UTF-8" >
< meta
name = "viewport"
content = "width=device-width, initial-scale=1.0" >
< title > 贪吃蛇游戏 < / title >
< style >
body
{
    display: flex;
flex - direction: column;
align - items: center;
justify - content: center;
height: 100
vh;
margin: 0;
background - color:  # f0f0f0;
font - family: Arial, sans - serif;
}

h1
{
    color:  # 333;
        margin - bottom: 20
px;
}

# game-container {
position: relative;
}

# game-canvas {
border: 2
px
solid  # 333;
background - color:  # fff;
}

# score-display {
margin - top: 20
px;
font - size: 24
px;
color:  # 333;
}

# game-over {
position: absolute;
top: 50 %;
left: 50 %;
transform: translate(-50 %, -50 %);
background - color: rgba(0, 0, 0, 0.8);
color: white;
padding: 20
px;
border - radius: 10
px;
text - align: center;
display: none;
}

# restart-btn {
margin - top: 15
px;
padding: 10
px
20
px;
background - color:  # 4CAF50;
color: white;
border: none;
border - radius: 5
px;
cursor: pointer;
font - size: 16
px;
}

# restart-btn:hover {
background - color:  # 45a049;
}

.controls
{
    margin - top: 20px;
text - align: center;
}

.controls
p
{
    margin: 5px 0;
color:  # 555;
}
< / style >
    < / head >
        < body >
        < h1 > 贪吃蛇游戏 < / h1 >

                              < div
id = "game-container" >
     < canvas
id = "game-canvas"
width = "400"
height = "400" > < / canvas >
                     < div
id = "game-over" >
     < h2 > 游戏结束! < / h2 >
                          < p
id = "final-score" > 得分: 0 < / p >
                                 < button
id = "restart-btn" > 重新开始 < / button >
                                  < / div >
                                      < / div >

                                          < div
id = "score-display" > 得分: 0 < / div >

                                   < div


class ="controls" >

< p > 使用方向键或WASD控制蛇的移动 < / p >
< p > 吃到食物增加得分，避免撞墙或撞到自己 < / p >
< / div >

< script >
document.addEventListener('DOMContentLoaded', () = > {
    const
canvas = document.getElementById('game-canvas');
const
ctx = canvas.getContext('2d');
const
scoreDisplay = document.getElementById('score-display');
const
gameOverDisplay = document.getElementById('game-over');
const
finalScoreDisplay = document.getElementById('final-score');
const
restartBtn = document.getElementById('restart-btn');

// 游戏参数
const
gridSize = 20;
const
tileCount = canvas.width / gridSize;
let
score = 0;

// 蛇的初始状态
let
snake = [
    {x: 10, y: 10}
];
let
velocityX = 0;
let
velocityY = 0;

// 食物位置
let
foodX = 5;
let
foodY = 5;

// 游戏状态
let
gameRunning = true;

// 游戏循环
function
gameLoop()
{
if (gameRunning)
{
    update();
draw();
}
setTimeout(gameLoop, 100);
}

// 更新游戏状态
function
update()
{
// 移动蛇
const
head = {x: snake[0].x + velocityX, y: snake[0].y + velocityY};
snake.unshift(head);

// 检查是否吃到食物
if (head.x === foodX & & head.y == = foodY)
{
    score += 10;
scoreDisplay.textContent = `得分: ${score}
`;
placeFood();
} else {
    snake.pop();
}

// 检查碰撞
if (
        head.x < 0 | | head.x >= tileCount | |
        head.y < 0 | | head.y >= tileCount | |
        checkCollision(head.x, head.y, snake.slice(1))
)
{
    gameOver();
}
}

// 绘制游戏
function
draw()
{
// 清空画布
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, canvas.width, canvas.height);

// 绘制网格线
ctx.strokeStyle = '#eee';
ctx.lineWidth = 0.5;
for (let i = 0; i < tileCount; i++)
{
    ctx.beginPath();
ctx.moveTo(i * gridSize, 0);
ctx.lineTo(i * gridSize, canvas.height);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(0, i * gridSize);
ctx.lineTo(canvas.width, i * gridSize);
ctx.stroke();
}

// 绘制蛇
ctx.fillStyle = '#4CAF50';
snake.forEach(segment= > {
    ctx.fillRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
ctx.strokeStyle = '#45a049';
ctx.strokeRect(segment.x * gridSize, segment.y * gridSize, gridSize, gridSize);
});

// 绘制食物
ctx.fillStyle = '#f44336';
ctx.beginPath();
const
centerX = foodX * gridSize + gridSize / 2;
const
centerY = foodY * gridSize + gridSize / 2;
ctx.arc(centerX, centerY, gridSize / 2 - 2, 0, Math.PI * 2);
ctx.fill();
}

// 放置食物
function
placeFood()
{
    let
validPosition = false;

while (!validPosition) {
foodX = Math.floor(Math.random() * tileCount);
foodY = Math.floor(Math.random() * tileCount);

// 确保食物不会出现在蛇身上
validPosition = !checkCollision(foodX, foodY, snake);
}
}

// 检查碰撞
function
checkCollision(x, y, array)
{
return array.some(segment= > segment.x === x & & segment.y == = y);
}

// 游戏结束
function
gameOver()
{
gameRunning = false;
finalScoreDisplay.textContent = `得分: ${score}
`;
gameOverDisplay.style.display = 'block';
}

// 重新开始游戏
function
resetGame()
{
snake = [{x: 10, y: 10}];
velocityX = 0;
velocityY = 0;
score = 0;
scoreDisplay.textContent = `得分: ${score}
`;
placeFood();
gameOverDisplay.style.display = 'none';
gameRunning = true;
}

// 键盘控制
document.addEventListener('keydown', (e) = > {
                                             // 防止按键导致页面滚动
if ([37, 38, 39, 40, 65, 87, 68, 83].includes(e.keyCode))
{
    e.preventDefault();
}

// 方向键控制
if (e.keyCode === 37 | | e.keyCode == = 65)
{ // 左箭头或A
if (velocityX !== 1)
{
    velocityX = -1;
velocityY = 0;
}
} else if (e.keyCode === 38 | | e.keyCode == = 87) {// 上箭头或W
if (velocityY != = 1) {
velocityX = 0;
velocityY = -1;
}
} else if (e.keyCode == = 39 | | e.keyCode == = 68) {// 右箭头或D
if (velocityX != = -1) {
velocityX = 1;
velocityY = 0;
}
} else if (e.keyCode == = 40 | | e.keyCode == = 83) {// 下箭头或S
if (velocityY != = -1) {
velocityX = 0;
velocityY = 1;
}
}
});

// 重新开始按钮
restartBtn.addEventListener('click', resetGame);

// 开始游戏
placeFood();
gameLoop();
});
< / script >
< / body >
< / html >
```

## 游戏说明

1. ** 游戏控制 ** ：
- 使用键盘方向键(↑↓←→)或WASD键控制蛇的移动
- 蛇不能反向移动(例如不能从左直接转向右)

2. ** 游戏规则 ** ：
- 吃到红色食物增加10分
- 蛇会随着吃到食物而变长
- 撞到墙壁或自己的身体会导致游戏结束

3. ** 游戏界面 ** ：
- 顶部显示当前得分
- 游戏结束时会显示最终得分和重新开始按钮
- 底部有简单的操作说明

4. ** 游戏特点 ** ：
- 响应式设计，适合在不同设备上显示
- 简洁美观的界面
- 网格背景便于判断位置

你可以将这段代码复制到一个HTML文件中，然后在浏览器中打开即可开始游戏。
'''
# 以正则匹配的方式，将代码中的html部分提取出来
html = re.findall(r'```html(.*?)```', s, re.DOTALL)[0]
print( html)
